﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Configuration;

public partial class SalesUserDashboards : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ToString());
    
    protected void Page_Load(object sender, EventArgs e)
    {
        logpeople.Text = (string)Session["Username"];
        if (Session["Authentication"] == null)
        {
            Response.Redirect("~/AdminLogin.aspx");
        }
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string filename = Path.GetFileName(fileUpload1.PostedFile.FileName);
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "MAS_pInventryDetailsInsert";
        cmd.Parameters.Add(new SqlParameter("@Product", SqlDbType.VarChar)).Value = saveproduct.Text;
        cmd.Parameters.Add(new SqlParameter("@Brand", SqlDbType.VarChar)).Value = saveBrand.Text;
        cmd.Parameters.Add(new SqlParameter("@Model", SqlDbType.VarChar)).Value = saveModel.Text;
        cmd.Parameters.Add(new SqlParameter("@Series", SqlDbType.VarChar)).Value = saveSeries.Text;
        cmd.Parameters.Add(new SqlParameter("@Color", SqlDbType.VarChar)).Value = savecolor.Text;
        cmd.Parameters.Add(new SqlParameter("@MotherBoard", SqlDbType.VarChar)).Value = motherBoard.Text;
        cmd.Parameters.Add(new SqlParameter("@Processor", SqlDbType.VarChar)).Value = saveprocessor.Text;
        cmd.Parameters.Add(new SqlParameter("@Ram", SqlDbType.VarChar)).Value = saveRAM.Text;
        cmd.Parameters.Add(new SqlParameter("@ScreenType", SqlDbType.VarChar)).Value = saveScreenType.Text;
        cmd.Parameters.Add(new SqlParameter("@ScreenSize", SqlDbType.VarChar)).Value = saveScreenSize.Text;
        cmd.Parameters.Add(new SqlParameter("@OpticalDiskdrive", SqlDbType.VarChar)).Value = saveOpticalDiskDrive.Text;
        cmd.Parameters.Add(new SqlParameter("@Usb", SqlDbType.VarChar)).Value = saveUSB.Text;
        cmd.Parameters.Add(new SqlParameter("@ModemEthernet", SqlDbType.VarChar)).Value = saveModemEthernet0.Text;
        cmd.Parameters.Add(new SqlParameter("@Bluetooth", SqlDbType.VarChar)).Value = saveBluetooth.Text;
        cmd.Parameters.Add(new SqlParameter("@TVOutput", SqlDbType.VarChar)).Value = saveTVoutput.Text;
        cmd.Parameters.Add(new SqlParameter("@SoundCard", SqlDbType.VarChar)).Value = saveSound.Text;
        cmd.Parameters.Add(new SqlParameter("@KeyboardAndMouse", SqlDbType.VarChar)).Value = saveKeyboardMouse.Text;
        cmd.Parameters.Add(new SqlParameter("@Accessories", SqlDbType.VarChar)).Value = saveAccessoriesIncluded.Text;
        cmd.Parameters.Add(new SqlParameter("@OperatingSystem", SqlDbType.VarChar)).Value = saveOperatingSystem.Text;
        cmd.Parameters.Add(new SqlParameter("@GraphicsCard", SqlDbType.VarChar)).Value = saveGrapicsCard.Text;
        cmd.Parameters.Add(new SqlParameter("@HardDrive", SqlDbType.VarChar)).Value = saveHardDrive.Text;
        cmd.Parameters.Add(new SqlParameter("@ScreenResolution", SqlDbType.VarChar)).Value = saveScreenResolution.Text;
        cmd.Parameters.Add(new SqlParameter("@MemoryCardReader", SqlDbType.VarChar)).Value = saveMemoryCardReader.Text;
        cmd.Parameters.Add(new SqlParameter("@Wifi", SqlDbType.VarChar)).Value = saveWiFi.Text;
        cmd.Parameters.Add(new SqlParameter("@AudioInterface", SqlDbType.VarChar)).Value = saveAudioInterface.Text;
        cmd.Parameters.Add(new SqlParameter("@ExpantionCardSlot", SqlDbType.VarChar)).Value = saveExpansonCardSlot.Text;
        cmd.Parameters.Add(new SqlParameter("@Webcam", SqlDbType.VarChar)).Value = saveWebcam.Text;
        cmd.Parameters.Add(new SqlParameter("@Battery", SqlDbType.VarChar)).Value = saveBattery.Text;
        cmd.Parameters.Add(new SqlParameter("@SoftwareIncluded", SqlDbType.VarChar)).Value = saveSoftwareIncluded.Text;
        cmd.Parameters.Add(new SqlParameter("@Price", SqlDbType.Float)).Value = savePrice.Text;
        cmd.Parameters.Add(new SqlParameter("@Discount", SqlDbType.Float)).Value = saveDiscount.Text;
        cmd.Parameters.Add(new SqlParameter("@Homedelivery", SqlDbType.Int)).Value = 1;
        cmd.Parameters.AddWithValue("@Path", "Files/" + filename);
        cmd.Parameters.Add(new SqlParameter("@Person", SqlDbType.VarChar)).Value = logpeople.Text;
        SqlDataAdapter sqa = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        sqa.Fill(dt);
        con.Close();
        fileUpload1.SaveAs(Server.MapPath("Files/" + filename));


        //string filename = Path.GetFileName(fileUpload1.PostedFile.FileName);
        //fileUpload1.SaveAs(Server.MapPath("Files/" + filename));
            
        //    con.Open();
        //    DataSet ds = new DataSet();
        //    SqlCommand cmd = new SqlCommand("insert into MAS_tInventryDetails(FileName,FilePath) values(@FileName,@FilePath)", con);
            
            
        //    cmd.ExecuteNonQuery();
            
        //    cmd.Connection = con;
        //    cmd.CommandType = CommandType.StoredProcedure;
        //    cmd.CommandText = "MAS_pInventryDetailsInsert";
        //    cmd.Parameters.Add(new SqlParameter("@Product", SqlDbType.VarChar)).Value = saveproduct.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Brand", SqlDbType.VarChar)).Value = saveBrand.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Model", SqlDbType.VarChar)).Value = saveModel.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Series", SqlDbType.VarChar)).Value = saveSeries.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Color", SqlDbType.VarChar)).Value = savecolor.Text;
        //    cmd.Parameters.Add(new SqlParameter("@MotherBoard", SqlDbType.VarChar)).Value = motherBoard.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Processor", SqlDbType.VarChar)).Value = saveprocessor.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Ram", SqlDbType.VarChar)).Value = saveRAM.Text;
        //    cmd.Parameters.Add(new SqlParameter("@ScreenType", SqlDbType.VarChar)).Value = saveScreenType.Text;
        //    cmd.Parameters.Add(new SqlParameter("@ScreenSize", SqlDbType.VarChar)).Value = saveScreenSize.Text;
        //    cmd.Parameters.Add(new SqlParameter("@OpticalDiskdrive", SqlDbType.VarChar)).Value = saveOpticalDiskDrive.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Usb", SqlDbType.VarChar)).Value = saveUSB.Text;
        //    cmd.Parameters.Add(new SqlParameter("@ModemEthernet", SqlDbType.VarChar)).Value = saveModemEthernet0.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Bluetooth", SqlDbType.VarChar)).Value = saveBluetooth.Text;
        //    cmd.Parameters.Add(new SqlParameter("@TVOutput", SqlDbType.VarChar)).Value = saveTVoutput.Text;
        //    cmd.Parameters.Add(new SqlParameter("@SoundCard", SqlDbType.VarChar)).Value = saveSound.Text;
        //    cmd.Parameters.Add(new SqlParameter("@KeyboardAndMouse", SqlDbType.VarChar)).Value = saveKeyboardMouse.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Accessories", SqlDbType.VarChar)).Value = saveAccessoriesIncluded.Text;
        //    cmd.Parameters.Add(new SqlParameter("@OperatingSystem", SqlDbType.VarChar)).Value = saveOperatingSystem.Text;
        //    cmd.Parameters.Add(new SqlParameter("@GraphicsCard", SqlDbType.VarChar)).Value = saveGrapicsCard.Text;
        //    cmd.Parameters.Add(new SqlParameter("@HardDrive", SqlDbType.VarChar)).Value = saveHardDrive.Text;
        //    cmd.Parameters.Add(new SqlParameter("@ScreenResolution", SqlDbType.VarChar)).Value = saveScreenResolution.Text;
        //    cmd.Parameters.Add(new SqlParameter("@MemoryCardReader", SqlDbType.VarChar)).Value = saveMemoryCardReader.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Wifi", SqlDbType.VarChar)).Value = saveWiFi.Text;
        //    cmd.Parameters.Add(new SqlParameter("@AudioInterface", SqlDbType.VarChar)).Value = saveAudioInterface.Text;
        //    cmd.Parameters.Add(new SqlParameter("@ExpantionCardSlot", SqlDbType.VarChar)).Value = saveExpansonCardSlot.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Webcam", SqlDbType.VarChar)).Value = saveWebcam.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Battery", SqlDbType.VarChar)).Value = saveBattery.Text;
        //    cmd.Parameters.Add(new SqlParameter("@SoftwareIncluded", SqlDbType.VarChar)).Value = saveSoftwareIncluded.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Price", SqlDbType.Float)).Value = savePrice.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Discount", SqlDbType.Float)).Value = saveDiscount.Text;
        //    cmd.Parameters.Add(new SqlParameter("@Homedelivery", SqlDbType.Int)).Value = saveHomeDelivery.Text;
        //    cmd.Parameters.AddWithValue("@FileName", filename);
        //    cmd.Parameters.AddWithValue("@FilePath", "Files/" + filename);
            
            
            
        //    SqlDataAdapter sda = new SqlDataAdapter(cmd);
          
        //    sda.Fill(ds);
            
        //    con.Close();
        //    Response.Redirect("~/SalesUserDashboards.aspx");

        }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Session.Clear();
        if (Request.Cookies["MyCookie"] != null)
        {
            var c = new HttpCookie("MyCookie");
            c.Expires = DateTime.Now.AddDays(-1);
            Response.Cookies.Add(c);
        }

        Session.Abandon();
        Response.Cookies.Clear();

        Response.Redirect("AdminLogin.aspx", true);


    }
}
